package com.crack.nga2.utils;

import android.os.Handler;
import android.os.HandlerThread;
import android.os.Looper;


/**
 * 一个工作线程 包含一个与其关联的Handler
 * Created by Administrator on 2015/12/15.
 */
public class WorkHandler extends Handler {
    private static HandlerThread workThread;

    public WorkHandler() {
        this(getWorkLooper());
    }

    public WorkHandler(Looper looper) {
        super(looper);
    }

    private static Looper getWorkLooper() {
        if (workThread == null || !workThread.isAlive()) {
            workThread = new HandlerThread("work");
            workThread.start();
        }
        return workThread.getLooper();
    }

    public void quit(){
        workThread.quit();
    }
}
